package com.lsf.studentmanagerup.servlet.student;

import com.lsf.studentmanagerup.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 检查学号是否重复
 *
 * @author 李树飞
 */
@WebServlet(name = "CheckStudentServlet", urlPatterns = "/checkStudent")
public class CheckStudentServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=UTF-8");

        //获取想客户端发送字符文本的对象
        PrintWriter writer = response.getWriter();

        //获取请求中参数的id
        String studentId = request.getParameter("studentId");
        //调用服务层的验证方法
        StudentService studentService = new StudentService();

        //返回给客户端
        writer.print(studentService.checkStudent(studentId));
        writer.flush();
        writer.close();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
